package archive

import (
	"compress/flate"
	"io"
)

var Flate = &compressFlate{}

type compressFlate struct {
	level int
}

func (receiver *compressFlate) Reader(reader io.Reader) io.Reader {
	flateReader := flate.NewReader(reader)
	defer flateReader.Close()

	return flateReader
}
func (receiver *compressFlate) ReaderDict(reader io.Reader) io.Reader {
	flateReader := flate.NewReaderDict(reader, []byte{})
	defer flateReader.Close()

	return flateReader
}
func (receiver *compressFlate) Writer(writer io.Writer) (io.Writer, error) {
	flateWriter, err := flate.NewWriter(writer, receiver.level)
	defer flateWriter.Close()

	return flateWriter, err
}
func (receiver *compressFlate) WriterDict(writer io.Writer) (io.Writer, error) {
	flateWriter, err := flate.NewWriterDict(writer, receiver.level, []byte{})
	defer flateWriter.Close()

	return flateWriter, err
}

func (receiver *compressFlate) SetLevel(level int) *compressFlate {
	receiver.level = level

	return receiver
}
